Skip to content

fix: show in-flight expect.poll on test timeout error#10137

Draft
hi-ogawa wants to merge 1 commit intovitest-dev:mainfrom
hi-ogawa:feat-surface-in-flight-expect-poll-on-test-timeout-error
Draft

fix: show in-flight expect.poll on test timeout error#10137
hi-ogawa wants to merge 1 commit intovitest-dev:mainfrom
hi-ogawa:feat-surface-in-flight-expect-poll-on-test-timeout-error

Conversation

@hi-ogawa
Copy link
Copy Markdown
Collaborator

@hi-ogawa hi-ogawa commented Apr 13, 2026

Description

I found a case where I want to surface what's pending on test timeout and this is possible by hooking in to context.signal. My scenario wasn't actually expect.poll but something similar to our test-util's waitForOutput.

This PR adds such helper-ish method as context.recordErrorOnTimeout and also this can be used for surfacing in-flight expect.poll, which I think can be useful too.

What's convenient about context.recordErrorOnTimeout is that it allows custom async assertion to not need to estimate and hard-code right own timeout to be triggered before test timeout.

Please don't delete this checklist! Before submitting the PR, please make sure you do the following:

  • It's really useful if your PR references an issue where it is discussed ahead of time. If the feature is substantial or introduces breaking changes without a discussion, PR might be closed.
  • Ideally, include a test that fails without this PR but passes with it.
  • Please, don't make changes to pnpm-lock.yaml unless you introduce a new test example.
  • Please check Allow edits by maintainers to make review process faster. Note that this option is not available for repositories that are owned by Github organizations.

Tests

  • Run the tests with pnpm test:ci.

Documentation

  • If you introduce new functionality, document it. You can run documentation with pnpm run docs command.

Changesets

  • Changes in changelog are generated from PR name. Please, make sure that it explains your changes in an understandable manner. Please, prefix changeset messages with feat:, fix:, perf:, docs:, or chore:.

@netlify
Copy link
Copy Markdown

netlify Bot commented Apr 13, 2026

Deploy Preview for vitest-dev ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 2d10c54
🔍 Latest deploy log https://app.netlify.com/projects/vitest-dev/deploys/69dcc7eb83bfbc0008d85921
😎 Deploy Preview https://deploy-preview-10137--vitest-dev.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

Comment on lines +252 to +269
function recordErrorOnTimeout(createError: () => unknown) {
const addError = () => {
// as cause?
// const timeoutError = context.signal.reason as Error;
// if (!timeoutError.cause) {
// timeoutError.cause = createError()
// }

// or as stack?
const timeoutError = context.signal.reason as Error
if (timeoutError && timeoutError.stack) {
copyStackTrace(timeoutError, createError() as any)
}

// or as dedicated error?
// recordError(createError())
}
context.signal.addEventListener('abort', addError)
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are the three variants:

  • as cause
 FAIL  test/repro.test.ts > repro
Error: Test timed out in 2000ms.
If this is a long-running test, pass a timeout value as the last argument or configure it globally with "testTimeout".
 ❯ test/repro.test.ts:3:1
      1| import { expect, test } from 'vitest'
      2|
      3| test('repro', { timeout: 2000 }, async () => {
       | ^
      4|   await expect.poll(async () => {
      5|     return 4321

Caused by: Error: expect.poll did not succeed in time.
 ❯ test/repro.test.ts:6:26
  • as stack
 FAIL  test/repro.test.ts > repro
Error: Test timed out in 2000ms.
If this is a long-running test, pass a timeout value as the last argument or configure it globally with "testTimeout".
 ❯ test/repro.test.ts:6:26
      4|   await expect.poll(async () => {
      5|     return 4321
      6|   }, { timeout: 10000 }).toBe(1234)
       |                          ^
      7| })
      8|
  • as a separate error
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Failed Tests 1 ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯

 FAIL  test/repro.test.ts > repro
Error: expect.poll did not succeed in time.
 ❯ test/repro.test.ts:6:26
      4|   await expect.poll(async () => {
      5|     return 4321
      6|   }, { timeout: 10000 }).toBe(1234)
       |                          ^
      7| })
      8|

⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[1/2]⎯

 FAIL  test/repro.test.ts > repro
Error: Test timed out in 2000ms.
If this is a long-running test, pass a timeout value as the last argument or configure it globally with "testTimeout".
 ❯ test/repro.test.ts:3:1
      1| import { expect, test } from 'vitest'
      2|
      3| test('repro', { timeout: 2000 }, async () => {
       | ^
      4|   await expect.poll(async () => {
      5|     return 4321

⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[2/2]⎯

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Surface in-flight expect.poll on test timeout error

1 participant